<template>
<div class="mui-content">
    <div id="slider" class="mui-slider">
        <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
            <div class="mui-scroll">
                <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" v-for="item in categorys" :key="item.id" @tap="getPhotoListByCateId(item.id)">
                    {{ item.title }}
                </a>
            </div>
        </div>

    </div>
</div>
</template>

<script>
import mui from "../../lib/mui/js/mui.min.js";
export default {

    data() {
        return {
            categorys: []
        };
    },
    methods: {
        getAllCategory() {
            // 获取所有的图片分类
            this.$http.get("api/getimgcategory").then(result => {
                if (result.body.status === 0) {
                    // 手动拼接出一个最完整的 分类列表
                    result.body.message.unshift({
                        title: "全部",
                        id: 0
                    });
                    this.categorys = result.body.message;
                }
            });
        },
        getPhotoListByCateId(cateId) {
            // 根据 分类Id，获取图片列表
            this.$http.get("api/getimages/" + cateId).then(result => {
                if (result.body.status === 0) {
                    this.list = result.body.message;
                }
            });
        }
    },
    created() {
        this.getAllCategory();
        this.getPhotoListByCateId(0);
    },
    mounted() {
        mui(".mui-scroll-wrapper").scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });
    },
};
</script>

<style>
</style>
